package com.nf.practice.service.impl;

import com.nf.practice.common.handler.GuliException;
import com.nf.practice.entity.User;
import com.nf.practice.mapper.UserMapper;
import com.nf.practice.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;


    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public int deleteUser(Integer id) {
        return userMapper.deleteUser(id);
    }

    @Override
    public int saveUser(User user) {
//        saveTUser(user); 测试Transactional注解用在private方法上会失效
        userMapper.saveUser(user);
        this.B();
//        int i = 1/0;
        return 0;
    }

    @Transactional
    public void B() {
//        userMapper.saveUser(new User("十三",17,"男","176cm"));
        int i = 1/0;
    }

//    @Transactional
//    private void saveTUser(User user) {
//        userMapper.saveUser(user);
//    }

    @Override
    public List<User> queryAllUser() {
        List<User> list = userMapper.queryAllUser();
        return list;
    }


}
